<?php

namespace App\Models\users;

use App\Models\BaseModel;
use Illuminate\Database\Eloquent\Casts\Attribute;
use lxs\tools\Tools;


class UsersWithdrawOrderModel extends BaseModel
{
    protected $table = 'users_withdraw_order';
    protected $primaryKey = 'id';

    const WITHDRAW_APPLYING = 1; // 申请中
    const WITHDRAW_REFUSE = 2; // 已驳回
    const WITHDRAW_SUCCESS = 3; // 成功

    const WITHDRAW_TYPE = [
        'wechat_type' => 1,
        'bank_type' => 2,
        'alipay_type' => 3,
    ];

    public static function getwithdrawType($value=''): array|false|int|string
    {
        $platform = [
            1 => '微信',
            2 => '银行卡',
            3 => '支付宝',
        ];
        if ( is_numeric($value) && $value > 0 && $value < 6 ) {
            return $platform[$value];
        }
        if (is_string($value) && $value != '') {
            return array_search($value, $platform);
        }
        return $platform;
    }

    protected function createTime(): Attribute
    {
        return Attribute::make(
            get: fn (string $value) => Tools::timeConvert($value)
        );
    }


    public function orderInfo(): \Illuminate\Database\Eloquent\Relations\HasOne
    {
        return $this->hasOne(UsersWithdrawOrderInfoModel::class, 'order_id', 'id');
    }

}
